<template>
  <div class="search">
    <div class="searchbox">
            <span @click="jiantou"><返回</span>
            <input type="text" placeholder="输入关键字" v-model="searchText">
            <span @click="search">搜索</span>
        </div>
        <div class="block">
            <div class="title">历史搜索</div>
            <div class="list">
                <span v-for="(item,index) in searchArr" :key="index">{{item}}</span>
            </div>
        </div>
        <div class="find">
             <div class="title">搜索发现</div>
             <div class="list">
                <span v-for="(item,index) in searchFind" :key="index">{{item}}</span>
             </div>
        </div>
        <div class="result" v-for="(item,index) in searchResult" :key="index">
             <span>{{item}}</span>
        </div>
  </div>
</template>

<script>
import { shop_search } from '@/utils/api'

export default {
    data(){
        return {
            searchText:'',
            searchArr:['三文鱼','刺身','生蚝'],
            searchFind:['麻辣烫','关东煮','烤山药','秘制果仁烤面筋','炒拉条'],
            searchResult:[]
        }
    },
    methods:{
        search(){
            shop_search({shop_search:this.searchText})
            .then((res)=>{
               this.searchResult=res.data.list
            })
            if( this.searchText ){
                this.searchArr.push( this.searchText );
                this.searchText = '';
            }
        },
        jiantou(){
            this.$router.push('/index');
        },

    }
}
</script>

<style>
.searchbox{
            margin: 10px;
            display: flex;
            align-items: center;
        }
        .searchbox input{
            flex:1;
            height: 40px;
            background-color: #f5f5f5;
            outline: none;
            border: none;
            padding-left: 20px;
            border-radius: 20px;
        }
        .searchbox span{
            width: 60px;
            text-align: center;
        }

        .block{
            margin: 10px;
        }
        .block .title{
            font-weight: bold;
            padding: 10px 0;
        }
        .block .list span{
            display: inline-block;
            background-color: #f5f5f5;
            padding: 5px 10px;
            border-radius: 5px;
            margin-right: 10px;
            margin-bottom: 10px;

        }
        .find{
            margin: 10px;
        }
        .find .title{
            font-weight: bold;
            padding: 10px 0;
        }
        .find .list span{
            display: inline-block;
            background-color: #f5f5f5;
            padding: 5px 10px;
            border-radius: 5px;
            margin-right: 10px;
            margin-bottom: 10px;

        }
</style>